package com.lzx.iteam.adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.baidu.mapapi.map.Text;
import com.lzx.iteam.AttendanceMemberActivity;
import com.lzx.iteam.PayToolsTeamActivity;
import com.lzx.iteam.R;
import com.lzx.iteam.bean.PayToolsData;
import com.lzx.iteam.bean.ScheduleManager;
import com.lzx.iteam.util.ImageLoaderInterface;
import com.lzx.iteam.util.StringUtil;

import java.util.ArrayList;

import static android.R.id.list;

/**
 * Created by Megan on 16/9/18.
 */
public class PayToolsAdapter extends BaseAdapter {
    private Context mContext;
    private ArrayList<PayToolsData> mPayToolsDatas;

    public PayToolsAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void bindData(ArrayList<PayToolsData> payToolsDatas){
        this.mPayToolsDatas=payToolsDatas;

    }

    @Override
    public int getCount() {
        return mPayToolsDatas==null?0:mPayToolsDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mPayToolsDatas==null?null:mPayToolsDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
       ViewHolder holder = null;
        final PayToolsData payToolsData = mPayToolsDatas.get(position);
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.pay_tools_item_layout, null);
            holder.name = (TextView) convertView.findViewById(R.id.tv_pay_tools_name);
            holder.price = (TextView) convertView.findViewById(R.id.tv_pay_tools_price);
            holder.description = (TextView) convertView.findViewById(R.id.tv_pay_tools_description);
            holder.upgrade = (TextView) convertView.findViewById(R.id.tv_pay_tools_upgrade);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.name.setText(payToolsData.getName());
        holder.price.setText(payToolsData.getPrice());
        holder.description.setText(payToolsData.getDescription());
        holder.upgrade.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                /*Intent intent=new Intent(mContext,PayToolsTeamActivity.class);
                intent.putExtra("payToolsData",payToolsData);
                mContext.startActivity(intent);*/
                Intent intent = new Intent();
                intent.setAction("android.intent.action.VIEW");
                String url = "https://item.taobao.com/item.htm?id=536371113281";
                Uri uri = Uri.parse(url);
                intent.setData(uri);
                mContext.startActivity(intent);
            }
        });
        return convertView;
    }

    private class ViewHolder {
        TextView name;
        TextView price;
        TextView description;
        TextView upgrade;
    }

}
